	function getCookie(cookieName) {
    var strCookie = document.cookie;
    var arrCookie = strCookie.split("; ");
    for(var i = 0; i < arrCookie.length; i++){
        var arr = arrCookie[i].split("=");
        if(cookieName == arr[0]){
            return arr[1];
        }
    }
    return "";
}
var str="";
var page = 0;
var offset = 0;
var pageSize = 5;
var j=5;
var userid=getCookie("userid");
var str2="<tr class='order-item'><td colspan='6'><div class='empty-msg'>最近没有任何订单，家里好像缺了点什么！<br><a href='item_category.html'>要不瞧瞧去？</a></div></td></tr>";
setTimeout(ggg(),100);

setTimeout(function(){
	$.ajax({
				url: "http://localhost:16111/orderform/juhe",
				mimeType: "post",
				dataType: "json",
				data:{
					userid:userid
				},
				xhrFields:{withCredentials: true},
				success: function(date) {
				
					localStorage.setItem("juh", date);

					if(date % pageSize == 0) {
//						alert("1");
							page = date / pageSize;
					} else {

//						alert("2");
//						alert("中" + zhong);
						page = Math.floor(date / pageSize+1);
						
					}
//alert(page);
				}
			});
	
	
},100);

function up(){
	if(offset-pageSize<0){
				alert("没有上一页");
				return;
			}else{
				offset=offset-pageSize;
				page=page+1;
			} 
//		alert(offset);
//		alert(page);
	$.ajax({
		type:"post",
		url:"http://localhost:16111/orderform/selectorder",
		data:{
			q:offset,
			j:j,
			userid:userid
		},
		xhrFields:{withCredentials: true},
		dataType:"json",
		success:function(date){
			console.log(date);
			if(date!=null){
			for (i in date) {
				if(date[i].statusbutton=="退货退款"){
					
				date[i].statusbuttonunder="";
				}else if(date[i].statusbutton=="评价"){
					
				date[i].statusbuttonunder="";
				}
				var xiatime=date[i].undertime;
				var time=new Date(xiatime);
				var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
				str+="<tr class='order-item'>"+
					"<td>"+
					"<label>"+
					"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='num'>"+time2+"&nbsp;&nbsp;订单号:"+ date[i].ordernumber +"</a>"+
					"<div class='card'>"+
						"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
						"<div class='name ep2'>"+date[i].comitydescription+"</div>"+
                        "<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+						"<div class='favour'>使用优惠券："+date[i].preferentialinformation+"</div>"+
					"</div>"+
					"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices+"</td>"+
					"<td>"+date[i].comitynumber+"</td>"+
					"<td>￥"+date[i].actualpayment+"<br><span class='fz12 c6 text-nowrap'>(含运费: ¥"+date[i].freight+")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>"+date[i].orderstatus+"</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"'   class='but c9'>订单详情"+"</a>"+
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span  onclick='deleteo("+date[i].orderid+")' class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						"<a  class='but but-primary' onclick=anniu(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\",\"" + date[i].spid + "\",\"" + date[i].specifications + "\",\"" + date[i].comityprices + "\",\"" + date[i].comitynumber + "\",\"" + date[i].comitypicture + "\")>"+date[i].statusbutton+"</a>"+
						"<a  class='but c3' onclick='fenfa(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\")'>"+date[i].statusbuttonunder+"</a>"+
					"</td>"+
				"</tr>";
			}
			document.getElementById("bodyy").innerHTML=str;
			str="";
			}else  if(str==""){
//			alert(str2);
			document.getElementById("bodyy").innerHTML=str2;
			}
		},
		error:function(){
			
			document.getElementById("bodyy").innerHTML=str2;
		}
		
});

}



function under(){
	       if(page==1){
				alert("没有下一页");
				return;
			}else{
				offset=offset+pageSize;
				page=page-1;
			} 

	$.ajax({
		type:"post",
		url:"http://localhost:16111/orderform/selectorder",
		data:{
			q:offset,
			j:j,
			userid:userid
		},
		xhrFields:{withCredentials: true},
		dataType:"json",
		success:function(date){
			console.log(date);
			if(date!=null){
			for (i in date) {
				if(date[i].statusbutton=="退货退款"){
					
				date[i].statusbuttonunder="";
				}else if(date[i].statusbutton=="评价"){
					
				date[i].statusbuttonunder="";
				}
				var xiatime=date[i].undertime;
				var time=new Date(xiatime);
				var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
//				var time=xiatime.getFullYear()+"-"+xiatime.getMonth()+"-"+xiatime.getDay();
				str+="<tr class='order-item'>"+
					"<td>"+
					"<label>"+
					"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='num'>"+time2+"&nbsp;&nbsp;订单号:"+ date[i].ordernumber +"</a>"+
					"<div class='card'>"+
						"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
						"<div class='name ep2'>"+date[i].comitydescription+"</div>"+
"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+						"<div class='favour'>使用优惠券："+date[i].preferentialinformation+"</div>"+
					"</div>"+
					"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices+"</td>"+
					"<td>"+date[i].comitynumber+"</td>"+
					"<td>￥"+date[i].actualpayment+"<br><span class='fz12 c6 text-nowrap'>(含运费: ¥"+date[i].freight+")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>"+date[i].orderstatus+"</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情"+"</a>"+
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span  onclick='deleteo("+date[i].orderid+")' class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						"<a  class='but but-primary' onclick=anniu(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\",\"" + date[i].spid + "\",\"" + date[i].specifications + "\",\"" + date[i].comityprices + "\",\"" + date[i].comitynumber + "\",\"" + date[i].comitypicture + "\")>"+date[i].statusbutton+"</a>"+
						"<a  class='but c3' onclick='fenfa(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\")'>"+date[i].statusbuttonunder+"</a>"+
						
					"</td>"+
				"</tr>";
			}
			document.getElementById("bodyy").innerHTML=str;
			str="";
			}else if(str==""){
//			alert(str2);
			document.getElementById("bodyy").innerHTML=str2;
			}
		},
		error:function(){
			
			document.getElementById("bodyy").innerHTML=str2;
		}
		
});


}



function ggg(){
	
	$.ajax({
		type:"post",
		url:"http://localhost:16111/orderform/selectorder",
		data:{
			q:0,
			j:j,
			userid:userid
		},
		xhrFields:{withCredentials: true},
		dataType:"json",
		success:function(date){
			console.log(date);
			if(date!=null){
			for (i in date) {
				if(date[i].statusbutton=="退货退款"){
					
				date[i].statusbuttonunder="";
				}else if(date[i].statusbutton=="评价"){
					
				date[i].statusbuttonunder="";
				}
				var xiatime=date[i].undertime;
				var time=new Date(xiatime);
				var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
//				var time=xiatime.getFullYear()+"-"+xiatime.getMonth()+"-"+xiatime.getDay();
				str+="<tr class='order-item'>"+
					"<td>"+
					"<label>"+
					"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='num'>"+time2+"&nbsp;&nbsp;订单号:"+ date[i].ordernumber +"</a>"+
					"<div class='card'>"+
						"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
						"<div class='name ep2'>"+date[i].comitydescription+"</div>"+
"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+						"<div class='favour'>使用优惠券："+date[i].preferentialinformation+"</div>"+
					"</div>"+
					"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices+"</td>"+
					"<td>"+date[i].comitynumber+"</td>"+
					"<td>￥"+date[i].actualpayment+"<br><span class='fz12 c6 text-nowrap'>(含运费: ¥"+date[i].freight+")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>"+date[i].orderstatus+"</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情"+"</a>"+
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span  onclick='deleteo("+date[i].orderid+")' class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						"<a  class='but but-primary' onclick=anniu(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\",\"" + date[i].spid + "\",\"" + date[i].specifications + "\",\"" + date[i].comityprices + "\",\"" + date[i].comitynumber + "\",\"" + date[i].comitypicture + "\")>"+date[i].statusbutton+"</a>"+
						"<a  class='but c3' onclick='fenfa(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\")'>"+date[i].statusbuttonunder+"</a>"+
					"</td>"+
				"</tr>";
			}
			document.getElementById("bodyy").innerHTML=str;
			str="";
			}else if(str==""){
//			alert(str2);
			document.getElementById("bodyy").innerHTML=str2;
			
			}
		},
		error:function(){
			
			document.getElementById("bodyy").innerHTML=str2;
		}
		
});
}


			
			
function deleteo(orderid){
	$.ajax({
		type:"post",
		url:"http://localhost:16111/orderform/deleteorder",
		dataType:"json",
		data:{
			orderid:orderid
		},
		xhrFields:{withCredentials: true},
		success:function(date){
			if(date=1){
				alert("删除成功");
				location.reload();
			}
		},
		error:function(){
			alert("删除失败");
		},
	});
}

function mohu(t){
	var zhi=t.value;
	if(zhi=="交易状态"){
		ggg();
		return;
	}
	$.ajax({
		type:"post",
		url:"http://localhost:16111/orderform/mohuselect",
		dataType:"json",
		data:{
			orderstatus:zhi,
			userid:userid
		},
		xhrFields:{withCredentials: true},
		success:function(date){
			console.log(date);
			if(date!=null){
			for (i in date){
				if(date[i].statusbutton=="退货退款"){
				date[i].statusbuttonunder="";
				}else if(date[i].statusbutton=="评价"){
					
				date[i].statusbuttonunder="";
				}
				var xiatime=date[i].undertime;
				var time=new Date(xiatime);
				var time2=time.getFullYear()+"-"+time.getMonth()+"-"+time.getDay();
//				var time=xiatime.getFullYear()+"-"+xiatime.getMonth()+"-"+xiatime.getDay();
				str+="<tr class='order-item'>"+
					"<td>"+
					"<label>"+
					"<a href='udai_order_detail.html' class='num'>"+time2+"&nbsp;&nbsp;订单号:"+ date[i].ordernumber +"</a>"+
					"<div class='card'>"+
						"<div class='img'><img src="+ date[i].comitypicture +" alt='' class='cover'></div>"+
						"<div class='name ep2'>"+date[i].comitydescription+"</div>"+
"<div class='format'>颜色/尺码：" +date[i].specifications+ "</div>"+						"<div class='favour'>使用优惠券："+date[i].preferentialinformation+"</div>"+
					"</div>"+
					"</label>"+
					"</td>"+
					"<td>￥"+date[i].comityprices+"</td>"+
					"<td>"+date[i].comitynumber+"</td>"+
					"<td>￥"+date[i].actualpayment+"<br><span class='fz12 c6 text-nowrap'>(含运费: ¥"+date[i].freight+")</span></td>"+
					"<td class='state'>"+
						"<a class='but c6'>"+date[i].orderstatus+"</a>"+
						"<a href='udai_order_detail.html?id="+date[i].orderid+"' class='but c9'>订单详情"+"</a>"+
					"</td>"+
					"<td class='order'>"+
						"<div class='del'><span  onclick='deleteo("+date[i].orderid+")' class='glyphicon glyphicon-trash' aria-hidden='true'></span></div>"+
						"<a  class='but but-primary' onclick=anniu(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\",\"" + date[i].spid + "\",\"" + date[i].specifications + "\",\"" + date[i].comityprices + "\",\"" + date[i].comitynumber + "\",\"" + date[i].comitypicture + "\")>"+date[i].statusbutton+"</a>"+
						"<a  class='but c3' onclick='fenfa(this,\"" + date[i].orderid + "\",\"" + date[i].ordernumber + "\")'>"+date[i].statusbuttonunder+"</a>"+
					"</td>"+
				"</tr>";
			}
			// alert("str"+str);
			document.getElementById("bodyy").innerHTML=str;
			str="";
			}else if(str==""){
//			alert(str2);
			document.getElementById("bodyy").innerHTML=str2;
			}
		},
		error:function(){
			
		},
	});
}

function fenfa(t,orderid,ordernumber){
	// alert(ordernumber);
	var wz=t.innerHTML;
	// alert(wz);
	if(wz=="取消订单"){
	localStorage.setItem("orderid",orderid);
	layui.use('layer', function() {
					var layer = layui.layer;
					layer.open({
						type: 2,
						title: '取消订单',
						fix: false,
						shadeClose: true,
						shade: 0.5,
						area: ['400px', '300px'],
						content: 'dcs.html',
						end: function() {
							
						}
					});
				});
	}
	if(wz=="退货退款"){
		localStorage.setItem("ordernumber",ordernumber)
		location.href="udai_apply_return.html"
	}
}

function anniu(t,orderid,ordernumber,spid,specifications,comityprices,comitynumber,comitypicture){
	var aizi=t.innerHTML;
	if(aizi=="立即付款"){
			$.ajax({
		type:"post",
		url:"http://127.0.0.1:16700/chams",
		data:{
			orderid:orderid
		},
		dateType:"json",
		success:function(date){
			
			var str = date;
	   		var arr = str.trim().split(" ");
	
	alert("商品规格==="+specifications);
	alert("商品价格==="+comityprices);
	alert("商品数量==="+comitynumber);
	alert("商品图片==="+comitypicture); 
	sessionStorage.setItem("orderid",orderid);
	window.location.href="udai_shopcart_pay.html?quantity_of_goods="+comitynumber+"&commodity_picture="+comitypicture+"&commodity_nametop="+arr[0]+"&commodity_description="+arr[1]+"&collection_item_price="+comityprices+"&commodity_leixin="+specifications+"&zt="+ordernumber;
		}
	});
	}
	if(aizi=="退货退款"){
		localStorage.setItem("ordernumber",ordernumber);
		location.href="udai_apply_return.html";
	}
	if(aizi=="确认收货"){
		location.href="udai_order_shou.html?id="+orderid;
	}
	
	if(aizi=="评价"){
		localStorage.setItem("orderid",orderid);
		localStorage.setItem("spid",spid);
		location.href='order_evaluate.html';
	}
}
